#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
检查PostgreSQL数据库表结构是否包含is_pushed字段
"""

from pg_models import PostgresTelegramDatabase

if __name__ == "__main__":
    # 初始化数据库连接
    db = PostgresTelegramDatabase()
    
    # 检查表结构
    conn = db.get_connection()
    if conn:
        try:
            cursor = conn.cursor()
            
            # 查询表结构
            cursor.execute("""
                SELECT column_name 
                FROM information_schema.columns 
                WHERE table_name = 'telegrams' 
                AND table_schema = 'public'
            """)
            
            columns = [row[0] for row in cursor.fetchall()]
            
            print("telegrams表包含以下字段:")
            for col in columns:
                print(f"- {col}")
            
            # 检查是否包含is_pushed字段
            if 'is_pushed' in columns:
                print("\n✓ 成功: is_pushed字段已添加到数据库表中")
            else:
                print("\n✗ 错误: is_pushed字段尚未添加到数据库表中")
            
        except Exception as e:
            print(f"查询表结构时出错: {e}")
        finally:
            cursor.close()
            conn.close()
    else:
        print("无法连接到数据库")